/**Created by the LayaAirIDE*/
module view.dlg{
	
	export class sign extends ui.dlg.signUI{
		private signConsume:number = 10;
		private weekNum:number;
		private dayOfWeek:number;
		private sizeSignNum:number;
		private signWeek:Array<number>;
		private signMonth:Array<number>;
		constructor(){
			super();

			this.close_btn.on(Laya.Event.MOUSE_DOWN, this, this.closeSign);
			this.diban.on(Laya.Event.CLICK,this,this.dibanFun);	
		}
		closeSign():void{
			this.close();
		}
		dibanFun():void{

		}
		//初始化签到表
		InitSignTable(weekNum:number,dayOfWeek:number,sizeSignNum:number,signWeek:Array<number>,signMonth:Array<number>):void{

			this.weekNum = weekNum;
			this.dayOfWeek = dayOfWeek;
			this.sizeSignNum = sizeSignNum;
			this.signWeek = signWeek;
			this.signMonth = signMonth;
			this.initLiHei();
			this.signStrip();
			for (let i:number = 0;i < this.signWeek.length;i++){
				
				var box:Laya.Box = this.getChildByName("item"+i) as Laya.Box;
				var background:Laya.Image = box.getChildByName("background") as Laya.Image;
				var jiangli:Laya.Image = box.getChildByName("jiangli") as Laya.Image;
				var stute:Laya.Image = box.getChildByName("stute") as Laya.Image;
				var buqian:Laya.Image = box.getChildByName("buqian") as Laya.Image;
				var textStute:Laya.Label = box.getChildByName("textStute") as Laya.Label;
				var weekColour:Laya.Label = box.getChildByName("weekColour") as Laya.Label;
				let parameter:Array<number> = [i];
				jiangli.on(Laya.Event.CLICK,this,this.signDo,parameter);				

				if (i < this.dayOfWeek){
					if (this.signWeek[i] == 0){
						//点击补签

						background.skin = "sign/jianglidiliang.png";
						background.visible = true;
						jiangli.skin = "item/" + Cfg.Sign[this.weekNum*7 +i]["pictureName"] + ".png";
						//jiangli.skin = "item/qiezi.png";
						jiangli.visible = true;
						// stute.skin = "sign/jifenbuqian.png";
						// stute.visible = true;
						buqian.visible = true;
						stute.visible = false;
						//textStute.text = "点击补签";
						textStute.visible = true;

					}else if (this.signWeek[i] == 1 || this.signWeek[i] == 2){
						//一签到  已领取
						background.skin = "sign/jianglidihui.png";
						background.visible = true;
						jiangli.skin = "item/" + Cfg.Sign[this.weekNum*7 +i]["pictureName"] + ".png";
						//jiangli.skin = "item/qiezi.png";
						jiangli.visible = true;
						stute.skin = "sign/yilingqv.png";
						buqian.visible = false;
						// if (this.signWeek[i] == 1){
						// 	stute.skin = "sign/yilingqv.png";
						// }else{
						// 	stute.skin = "sign/jifenbuqian.png";
						// }
						stute.visible = true;
						//textStute.text = "已领取";
						textStute.visible = true;
						//关闭鼠标点击事件 并变灰

					}

				}else if(i == this.dayOfWeek){
					//
					if (this.signWeek[i] == 1){
						//已签到
						if (this.dayOfWeek == 6){
							background.skin = "sign/dajianglihui.png";						
						}else{
							background.skin = "sign/jianglidihui.png";
						}
						
						background.visible = true;
						jiangli.skin = "item/" + Cfg.Sign[this.weekNum*7 +i]["pictureName"] + ".png";
						//jiangli.skin = "item/qiezi.png";
						jiangli.visible = true;
						stute.skin = "sign/yilingqv.png";
						stute.visible = true;
						buqian.visible = false;
						//textStute.text = "已领取";
						//textStute.visible = true;
						textStute.visible = true;
						//关闭鼠标点击事件 并变灰

					}else{
						//点击签到
						if (this.dayOfWeek == 6){
							background.skin = "sign/dajiangliliang.png";						
						}else{
							background.skin = "sign/jianglidiliang.png";
						}
						background.visible = true;
						jiangli.skin = "item/" + Cfg.Sign[this.weekNum*7 +i]["pictureName"] + ".png";
						//jiangli.skin = "item/qiezi.png";
						jiangli.visible = true;
						stute.visible = false;
						//textStute.text = "点击签到";
						textStute.visible = true;
						buqian.visible = false;
						//打开鼠标点击事
					}
				}else{
					//待签到
					
						if (this.dayOfWeek == 6){
							background.skin = "sign/dajiangliliang.png";						
						}else{
							background.skin = "sign/jianglidiliang.png";
						}
						background.visible = true;
						jiangli.skin = "item/" + Cfg.Sign[this.weekNum*7 +i]["pictureName"] + ".png";
						//jiangli.skin = "item/qiezi.png";
						jiangli.visible = true;
						stute.visible = false;
						//textStute.text = "待签到";
						textStute.visible = true;
						buqian.visible = false;
						//关闭鼠标点击事
				}
				textStute.text = "x " + Cfg.Sign[this.weekNum*7 +i]["num"];
				textStute.color = "#663504";
				textStute.bold = false;
				textStute.align = "center";
				textStute.fontSize = 18;
				weekColour.color = "#663504";
				weekColour.font = "Microsoft YaHei";
			}
			
		}
		
		initLiHei():void{
			for (let j = 0 ;j < 4;j++){
				var lihei:Laya.Image = this.getChildByName("lihei"+ j) as Laya.Image;

				let cntDay = (j+1) * 7;
				if (this.sizeSignNum < cntDay ){
					//灰色
					if (j == 3)
						lihei.skin = "sign/dalibaoan.png";
					else
						lihei.skin = "sign/lihean.png";
				}else if (this.signMonth[j] == 0){
					//亮色
					if (j == 3)
						lihei.skin = "sign/dalingbaoliang.png";
					else
						lihei.skin = "sign/liheliang.png";
					let parameter:Array<number> = [j];
					lihei.on(Laya.Event.CLICK,this,this.signMonthDo,parameter);
				}else if(this.signMonth[j] == 1){
					//领取成功
					if (j == 3 )
						lihei.skin = "sign/dalibaolingqv.png";
					else
						lihei.skin = "sign/lihelingqv.png";
				}
				//添加鼠标监听 显示

			}
		}
		signDo(day:number):void{
			//点击
			//判断积分是否够

			if (this.signWeek[day] != 0){
				return;
			}
			
			//this.parent.name
			let signType = 0;
			if (day < this.dayOfWeek && this.signWeek[day] == 0){
				signType = 2;
				let consume = 0
				for (let i =0; i< this.signWeek.length;i++){
					if (this.signWeek[i] == 2){
						consume += 1;
					}
				}
				//new

				let cnt = 2;
				for (let i =0 ;i< consume;i++){
					cnt *= 2;
				}	

				let consumeSecor = this.signConsume*(cnt);
			    let	yesNoJ:YesNo = new YesNo(signType,consumeSecor,day);
				yesNoJ.popup();
				return ;
			}else if (day == this.dayOfWeek && this.signWeek[day] == 0){
				signType = 1;
			}else{
				return ;
			}
			CtrlManager.GetCtrl(CtrlNames.Sign).sendSetSignNum(signType,day);
		}

		getSignPrize(signDay:number,type:number):void{
			let signPrize:SignPrize = new SignPrize(signDay,this.weekNum,0);
			var box:Laya.Box = this.getChildByName("item"+signDay) as Laya.Box;
			var background:Laya.Image = box.getChildByName("background") as Laya.Image;
			var jiangli:Laya.Image = box.getChildByName("jiangli") as Laya.Image;
			var stute:Laya.Image = box.getChildByName("stute") as Laya.Image;
			var buqian:Laya.Image = box.getChildByName("buqian") as Laya.Image;
			var textStute:Laya.Label = box.getChildByName("textStute") as Laya.Label;
			this.signWeek[signDay] = type;
			this.sizeSignNum += 1;
			this.signStrip();
			if (signDay == 6){
				background.skin = "sign/dajianglihui.png";						
			}else{
				background.skin = "sign/jianglidihui.png";
			}
			jiangli.gray = true;
			stute.skin = "sign/yilingqv.png";
			// if (type == 1){
			// 	stute.skin = "sign/yilingqv.png";
			// }else{
			// 	stute.skin = "sign/jifenbuqian.png";
			// }
			stute.visible = true;
			buqian.visible = false;
			// textStute.text = "已签到";
			// textStute.color = "#f1b313";
			textStute.bold = true;
			// textStute.fontSize = 18;
			//jiangli.mouseEnabled = false;
			this.initLiHei();
			signPrize.popup();
		}
		initialize	()	{
			this.width = 576;
			this.height = 1024;
			this.scaleX = 1.44;
			this.scaleY = 1.44;
		}	
		signMonthDo(cnt:number){
			if (this.signMonth[cnt] != 0){
				return;
			}
			CtrlManager.GetCtrl(CtrlNames.Sign).sendSignMonthPrize(cnt);
		}
		MonthPrize(cnt:number):void{
			var lihei:Laya.Image = this.getChildByName("lihei"+ cnt) as Laya.Image;
			
			if (cnt == 3 )
				lihei.skin = "sign/dalibaolingqv.png";
			else
				lihei.skin = "sign/lihelingqv.png";
			
			let signPrize:SignPrize = new SignPrize(cnt,this.weekNum,1);
			this.signMonth[cnt] = 1;
			signPrize.popup();
		}
		signStrip():void{
			this.strip.value = (this.sizeSignNum/28);
		}
	}
}